from rest_framework.generics import ListCreateAPIView

from apps.meiduo_admin.serializers.users import UserViewModelSerializers, UserViewSerializers
from apps.meiduo_admin.utils.MeiduoPage import PageNum
from apps.users.models import User


class UserView(ListCreateAPIView):
    pagination_class = PageNum
    # queryset = User.objects.filter(is_staff=False)
    serializer_class = UserViewModelSerializers
    def get_queryset(self):
        #self里有三个参数 request args kwargs
        key=self.request.query_params.get('keyword')

        return User.objects.filter(username__contains=key,is_staff=False)

    def get_serializer_class(self, *args, **kwargs):
        if self.request.method=='GET':
            return UserViewModelSerializers
        else:
            return UserViewSerializers
